Installing Kubernetes Using Kubeadm

What is Kubeadm?

Kubeadm is a tool built to simplify the process of bootstrapping a Kubernetes cluster on bare metal or virtual machines.


Installation Steps

1. Install Docker

Kubernetes uses Docker (or another container runtime) to run containers.

sudo apt update

sudo apt install docker.io -y


2. Install Kubeadm, Kubectl, and Kubelet

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt update

sudo apt install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl


3. Initialize the Master Node

sudo kubeadm init


4. Set Up Local kubeconfig

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config


5. Deploy Network Add-on

Kubernetes requires a network add-on like Calico or Flannel for communication between nodes.

kubectl apply -f

https://docs.projectcalico.org/manifests/calico.yaml


6. Join Worker Nodes

Run the join command provided after initializing the master node on each worker:

sudo kubeadm join <master-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>


Once done, your Kubernetes cluster is ready for deploying applications.


Working of Kubernetes

Once installed, Kubernetes manages containerized applications in an efficient and automated way. Let's understand its internal working:


Pods

A Pod is the smallest deployable unit in Kubernetes. It can contain one or more containers that share the same network namespace and storage.

For high availability, multiple replicas of the same pod can be created.


Services

A Service in Kubernetes acts as a load balancer that distributes traffic among healthy pods. It ensures that if one pod fails, the traffic automatically shifts to others.

Types of Services:

  • ClusterIP: Internal communication within the cluster
  • NodePort: Exposes services externally via a static port
  • LoadBalancer: Uses cloud provider's load balancer to expose services
  • ExternalName: Maps a service to an external DNS name

Ingress

Ingress manages external access to services within a cluster using HTTP and HTTPS routes

For example:

  • demo.com/image → Image Service
  • demo.com/video → Video Service

An Ingress Controller (like NGINX) must be installed to process these rules.


Example: Creating a Deployment

Here's a simple example of an NGINX deployment using YAML:


apiVersion: apps/v1
kind: Deployment
metadata:
 name: nginx-deployment
spec:
 replicas: 3
 selector:
   matchLabels:
    app: nginx
 template:
  metadata:
   labels:
    app: nginx
  spec:
   containers:
   - name: nginx
    image: nginx:1.7.9
    ports:
     - containerPort: 80


Deploy this configuration using:
kubectl create -f nginx.yaml

Check running pods:
kubectl get po


Conclusion

Kubernetes is the backbone of modern cloud-native architecture, simplifying container management and enabling auto-scaling, load balancing, and self-healing. Installing Kubernetes using Kubeadm gives you a powerful production-grade cluster setup in minutes.